Skip to content

Fix compile() raising TypeError for an out-of-range optimize - #1352

Open
jseop-lim wants to merge 1 commit into
oracle:masterfrom
jseop-lim:fix/compile-optimize-valueerror
Open

jseop-lim wants to merge 1 commit into
oracle:masterfrom
jseop-lim:fix/compile-optimize-valueerror

Conversation

@jseop-lim

Copy link
Copy Markdown
Contributor

Description

Part of #1291 (item 7).

CompileNode.checkOptimize raises TypeError with the message CPython uses for a ValueError (bltinmodule.c#L786-L789).

AS-IS

>>> compile('1', 'f', 'exec', optimize=5)
TypeError: compile(): invalid optimize value

TO-BE

>>> compile('1', 'f', 'exec', optimize=5)
ValueError: compile(): invalid optimize value

(matching CPython)

Changes

  • Raise ValueError in checkOptimize.
  • Add a test to tests/test_parser.py.

Testing

mx python-jvm on darwin-aarch64, then mx graalpytest on test_parser.py (the new test fails on the unpatched build and passes with the fix) and the tagged test_compile (77 passed). mx python-checkcopyrights, mx eclipseformat and mx checkstyle are clean.

compile(..., optimize=5) raised TypeError with the message CPython uses
for its ValueError.

Signed-off-by: Jeongseop Lim <jeongseop_lim@korea.ac.kr>
@oracle-contributor-agreement oracle-contributor-agreement Bot added the OCA Verified All contributors have signed the Oracle Contributor Agreement. label Nov 25, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

OCA Verified All contributors have signed the Oracle Contributor Agreement.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant